%% @doc templel_scan のテスト
%%
-module(t_templel_scan).
-import(templel_scan, [string/1]).

-include_lib("eunit/include/eunit.hrl").


string_test_() ->
	[?_assertMatch({ok,[],1},
				   string("")),
	 ?_assertMatch({ok,[],4}, 
				   string("\n\n\b\t\s\n")),
	 ?_assertMatch({ok,[{'.',[1]},{'[',[1]},{']',[1]},
						{'(',[2]},{',',[2]},{')',[2]},
						{'|',[3]},{'$',[3]},{'@',[3]},{'<',[3]},{'>',[3]},{'!',[3]}],3},
				   string(".[ ]\n  (, )\n|$@<>!")),

	 ?_assertMatch({ok,[{'==',[1]},{'==',[1]},{'==',[1]},
						{'!=',[1]},{'<=',[1]},{'<',[1]},{'>=',[1]},{'>',[1]},
						{'&&',[2]},{'||',[2]},{'!',[2]}],2},
				   string("======!=<=<>=> \n &&||!")),
	 ?_assertMatch({ok,[{'==',[1]},{'==',[1]},{'==',[1]},
						{'!=',[1]},{'<=',[1]},{'<',[1]},{'>=',[1]},{'>',[1]},
						{'&&',[2]},{'||',[2]},{'!',[2]}],2},
				   string("======!=<=<>=> \n &&||!")),

	 ?_assertMatch({ok,[{boolean,[1],true},{',',[1]},{boolean,[1],false}],1},
				   string("true,false")),
	 ?_assertMatch({ok,[{name,[1],"truefalse"}],1},
				   string("truefalse")),

	 ?_assertMatch({ok,[{integer,[1],0},{integer,[1],0},{integer,[1],1203}],1},
				   string("-001203")),
	 ?_assertMatch({ok,[{integer,[1],2222222222222222}],1},
				   string("2222222222222222")),

	 ?_assertMatch({ok,[{string,[1],[]}],1},
				   string("\"\"")),
	 ?_assertMatch({ok,[{string,[1],"hoge"}],1},
				   string("\"hoge\"")),
	 ?_assertMatch({error,{[1],templel_scan,{string,$","hog"}},1}, %"
				   string("\"hog")),
	 ?_assertMatch({ok,[{string,[1],"\"\b\n\t"}],2},
				   string("\"\\\"\b\n\t\"")),
	 ?_assertMatch({ok,[{string,[1],"\n\\\t"}],1},
				   string("\"\\n\\\\\\t\"")),
	 ?_assertError(badstate, string("\"\\a\"")),
	 ?_assertError(badstate, string("\"\\a")),
	 ?_assertMatch({ok,[{string,[1],"AȦ㊙"}],1}, 
				   string("\"\\u0041\\u0226\\u3299\"")),
	 ?_assertMatch({error,{[1],templel_scan,{string,$",[]}},1}, %"
				   string("\"\\")),
	 ?_assertError(badstate, string("\"\\u3B\"")),
	 ?_assertError(badstate, string("\"\\u3B")),

	 ?_assertMatch({ok,[{string,[1],"hoge"},{integer,[1],-10},{integer,[2],0},
				   {'[',[2]},{integer,[2],0},{']',[2]},{'.',[2]}],2},
				   string(" \ \"hoge\"-10\n0[0].")),
	 ?_assertMatch({ok,[{name,[1],"hoge"}],1},
				   string("hoge")),
	 ?_assertMatch({ok,[{name,[1],"h0g30_0"},{integer,[1],0}],1},
				   string("h0g30_0-0")),

	 ?_assertError(badstate, string("ほげ")),

	 ?_assertError(badstate, string("&")),
	 ?_assertError(badstate, string("*"))
	].
